#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=310;
int n,p,f[MAXN][MAXN],suma[MAXN],sumb[MAXN],ans;
int main()
{
	p=read();n=read();
	if(n==1)
	{
		puts("3");
		return 0;
	}
	for(int i=1;i<=n;++i)suma[i]=read()+suma[i-1],sumb[i]=read()+sumb[i-1];
	memset(f,INF,sizeof(f));ans=INF;
	for(int i=1;i<=n;++i)
		if(suma[i]<=p&&sumb[i]<=p)f[1][i]=1;
		else break;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=i;++j)
		{
			if(suma[i]-suma[j-1]>p||sumb[i]-sumb[j-1]>p)continue;
			for(int k=1;k<j;++k)
			{
				if(f[k][j-1]==INF)continue;
				f[j][i]=min(f[j][i],f[k][j-1]+2);
				if(suma[i]-suma[j-1]+sumb[j-1]-sumb[k-1]<=p)f[j][i]=min(f[j][i],f[k][j-1]+1);
			}
			if(i==n)ans=min(ans,f[j][i]);
		}
	printf("%d\n",ans+2);
	return 0;
}
